package br.com.statizo.financeiro.view;

import javax.annotation.PostConstruct;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.snoghertframework.swt.annotations.SnoghertComponent;
import org.snoghertframework.swt.converter.impl.SnoghertConverters;
import org.snoghertframework.swt.core.field.listener.ListenerVisitor;
import org.snoghertframework.swt.widgets.impl.SnoghertActionBar;
import org.snoghertframework.swt.widgets.impl.SnoghertCheckBox;
import org.snoghertframework.swt.widgets.impl.SnoghertCombo;
import org.snoghertframework.swt.widgets.impl.SnoghertDate;
import org.snoghertframework.swt.widgets.impl.SnoghertText;
import org.springframework.beans.factory.annotation.Autowired;


@SnoghertComponent
public class LancamentoComposite extends Composite{
 

	@Autowired
	private ListenerVisitor defaultListenerVisitor;
	
	private SnoghertDate dtPgto;
	private SnoghertDate dtDiv;
	private SnoghertCombo cbTipo;
	private SnoghertText txtCompl;
	private SnoghertText vlLanc;
	private SnoghertText nuParc;
	private SnoghertCombo cbTpPgto;
	private SnoghertCombo cbCc;
	private SnoghertCheckBox chkRec;
	private SnoghertCheckBox chkCtrl;
	private SnoghertCombo cbRec;
	private SnoghertCheckBox chkPg;
	
	public LancamentoComposite(Composite parent, int style){
		super(parent,style);
		
		setLayout(new RowLayout(SWT.VERTICAL));
		
		dtPgto = new SnoghertDate(this, SWT.BORDER, "lancController.lancamento.dataPagamento");
		dtPgto.setLabelText("Dt. Ptgto:");
		dtPgto.setLayoutData(new RowData());
		dtPgto.setConverter(SnoghertConverters.DATE_TIME_CONVERTER);

		dtDiv = new SnoghertDate(this, SWT.BORDER, "lancController.bean.dataDivida");
		dtDiv.setLayoutData(new RowData());
		dtPgto.setConverter(SnoghertConverters.DATE_TIME_CONVERTER);		
		
		cbTipo = new SnoghertCombo(this, SWT.NONE, "lancController.lancamento.informacao");
		cbTipo.setLayoutData(new RowData());		
		cbTipo.setConverter(SnoghertConverters.COMBO_CONVERTER);
		
		txtCompl = new SnoghertText(this, SWT.BORDER, "lancController.lancamento.complemento");
		txtCompl.setLayoutData(new RowData());
		txtCompl.setConverter(SnoghertConverters.TEXT_CONVERTER);		

		vlLanc = new SnoghertText(this, SWT.BORDER, "lancController.lancamento.valor");
		vlLanc.setLayoutData(new RowData());
		vlLanc.setConverter(SnoghertConverters.DOUBLE_CONVERTER);
		
		nuParc = new SnoghertText(this, SWT.BORDER, "lancController.nuParc");
		nuParc.setLayoutData(new RowData());
		nuParc.setConverter(SnoghertConverters.INTEGER_CONVERTER);
		
		cbTpPgto = new SnoghertCombo(this, SWT.NONE, "lancController.lancamento.tipoPagamento");
		cbTpPgto.setLayoutData(new RowData());
		cbTpPgto.setConverter(SnoghertConverters.COMBO_CONVERTER);
		
		cbCc = new SnoghertCombo(this, SWT.NONE, "lancController.lancamento.contaTransferencia");
		cbCc.setLayoutData(new RowData());
		cbCc.setConverter(SnoghertConverters.COMBO_CONVERTER);		
		
		chkRec = new SnoghertCheckBox(this, SWT.NONE,"lancController.recursoAlocado");
		chkRec.setLayoutData(new RowData());
		chkRec.setConverter(SnoghertConverters.CHECK_CONVERTER);
		
		chkCtrl = new SnoghertCheckBox(this, SWT.NONE,"lancController.lancamento.controleGastos");
		chkCtrl.setLayoutData(new RowData());
		chkCtrl.setConverter(SnoghertConverters.CHECK_CONVERTER);
		
		cbRec = new SnoghertCombo(this, SWT.NONE, "lancController.lancamento.recurso");
		cbRec.setLayoutData(new RowData());
		
		chkPg = new SnoghertCheckBox(this, SWT.NONE,"lancController.lancamento.pago");
		chkPg.setLayoutData(new RowData());
		chkPg.setConverter(SnoghertConverters.CHECK_CONVERTER);		
		
		SnoghertActionBar actionBar = new SnoghertActionBar(this, SWT.NONE);
		actionBar.setLayoutData(new RowData());
		
		actionBar.setEditBinding("lancController.edit");
		actionBar.setSaveBinding("lancController.save");
		
	}


	@PostConstruct
	protected void acceptValueBindings(){
		
		dtPgto.accept(defaultListenerVisitor);
		dtDiv.accept(defaultListenerVisitor);
		cbTipo.accept(defaultListenerVisitor);
		txtCompl.accept(defaultListenerVisitor);
		vlLanc.accept(defaultListenerVisitor);
		nuParc.accept(defaultListenerVisitor);
		cbTpPgto.accept(defaultListenerVisitor);
		cbCc.accept(defaultListenerVisitor);
		chkRec.accept(defaultListenerVisitor);
		chkCtrl.accept(defaultListenerVisitor);
		cbRec.accept(defaultListenerVisitor);
		chkPg.accept(defaultListenerVisitor);

	
	}
	
	
}